--
-- Author: shunguo.chen
-- Date: 2019-05-20 19:53:12
--
-- LegendPreView
--

local Armature = require("app.public.avatar.Armature")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.LegendPreScene

function ClassRef:init()
    self._ui.Button_close:addClickEventListener(function()
        executeFunc(self._onCloseView, self)
    end)

    display.uiAddClick(self._ui.Panel, function()
        executeFunc(self._onCloseView, self)
    end)
    
    self._activeColor = self._ui.name_1:getTextColor()
    self._unactiveColor = self._ui.name_2:getTextColor()
end

-- legend LegendVo
function ClassRef:refresh(legend)
    self._ui.title:setString(legend:getName())

    local fashions = legend.fashions
    local classId = legend:getClass()
    local offsetPos, offsetPosEx = legend:getAvatarOffsetPos()
    for i,fashion in ipairs(fashions) do
        local isActive = fashion:isActive()
        self._ui["name_" .. i]:setTextColor(isActive and self._activeColor or self._unactiveColor)

        local imgNode = self._ui["img_" .. i]
        -- imgNode:loadTexture(fashion:getBigIcon())
        imgNode:setVisible(false)
        local param = fashion:getAvatarParam()
        local armature = Armature.create(param)
        armature:setScale(param.scale)
        armature:setRotation(param.rotation)
        armature:playDefault()
        self._ui.Panel:addChild(armature)

        local posX, posY = imgNode:getPosition()
        armature:setPosition(posX + offsetPos[1], posY + offsetPos[2])
        if classId == 4 then
            -- 如果是刺客，显示两把武器
            local armatureEx = Armature.create(param)
            armatureEx:setScale(param.scale)
            armatureEx:setRotation(param.rotationEx)
            armatureEx:setPosition(posX + offsetPosEx[1], posY + offsetPosEx[2])
            armatureEx:playDefault()
            self._ui.Panel:addChild(armatureEx)
        end
    end
end

return ClassRef
